<?php
require_once(dirname(__FILE__)."../../users/config.php");
require_once("kill.php");
session_start();
$aid = isset($id) && is_numeric($id) ? $id : 0;
if(!defined('wwwew023com'))
{
ShowMsg("引入文件错误",'/');
exit();
	
}

if($aid=='0')
{
ShowMsg("参数错误,线路不存在",'/');
exit();
	
}

if($_SESSION['188yudingid']<>'gogo')
{
ShowMsg("错误，请不要越级操作",'/');
exit();
	
}

if($_COOKIE['buydd']=='188_'.$aid.'JD')
{
ShowMsg("您已经预订了改酒店，请不要重复预订",'/');
exit();
	
}


$AdultNum=$txtComeDate;
$KidNum=$txtOutDate;

for($i=0;$i<=$allid;$i++)
{
$arc='fxa'.$i;
$arcc='KidNum'.$i;
if($$arc<>'') $fx .= '|'.$$arc.'+'.$$arcc;// 如果选中
	
}
$date11=strtotime(''.$AdultNum.'');
$date22=strtotime(''.$KidNum.'');
if($date11-$date22>=0)
{
ShowMsg("预订时间错误，离开日期必须在到店日期之后",'-1');
exit();
}
$date33=($date22-$date11)/86400;

if($date33<=0) $date33=1;
$totalPrice=$totalPrice*$date33;

	
$buyid = '188_'.$aid.'JD'.mt_rand(1,99);

if(!$cfg_ml->IsLogin())
{ //如果没有登录

	    $row = $dsql->GetOne("Select mid From `#@__member` where mb='$contact_mobile' ");
		if(!is_array($row))
		{ //如果手机号码没有注册，则注册
		$rrss='Y';
		$jointime = time();
		$joinip = GetIP();	
		$pwd = md5($contact_mobile);
		$inQuery2 = "INSERT INTO `#@__member` (`pwd` ,`rank` ,`money` ,`jointime`, `joinip` ,`logintime`,`loginip`,`checkmail`,`mb`,`tjr`,`tel`,`email`)
	   VALUES ('$pwd','10','0',
	   '$jointime','$joinip','$jointime','$joinip','$checkmail','$contact_mobile','$tjr','$contact_phone','$contact_email'); ";
	   
	   if(!$dsql->ExecuteNoneQuery($inQuery2))
		{
			$gerr = $dsql->GetError();
			ShowMsg("把数据保存到数据库时出错<br>error:{$gerr}，请联系管理员！","javascript:;");
			exit();	
		}
		
		//----------------------------------------------
		//模拟登录
		//---------------------------
			$cfg_ml = new MemberLogin(7*3600);
			$rs = $cfg_ml->CheckUser($contact_mobile, $contact_mobile);
			
		}
		
}

$time=time();
$ip=getip();
		$inquery = "INSERT INTO `#@__order`(title,id,mid,buyid,ip,time,name,mb,tel,mail,jj,jiage,cr,rt,fx) Values('$title','$aid','".$cfg_ml->M_ID."','$buyid','$ip','$time','$contact_name','$contact_mobile','$contact_phone','$contact_email','$order_comment','$totalPrice','$AdultNum','$KidNum','$fx')";
		if(!$dsql->ExecuteNoneQuery($inquery))
		{
			$gerr = $dsql->GetError();
			ShowMsg("把数据保存到数据库时出错<br>error:{$gerr}，请联系管理员！","javascript:;");
			exit();
		}
		else
		{
		$pid='188_'.$aid.'JD';
		setcookie("buydd",$pid,time()+3600,"/");
		}


	    $makkk=$dsql->getone("select mb_3 from #@__mb where aid='0'");
		$mak1=$dsql->getone("select mb_1 from #@__mb where aid='1'");
		if($makkk['mb_3']=='1')
		{ // 发送短信
		$ombbb=okmbbb($aid,$buyid);
		}	
		
		if($mak1['mb_1']=='1' && $contact_email<>'')
		{ // 发送邮件
		$omb1=sendline($contact_email,$passwd,$contact_mobile,$aid);
		}
	


//$sql = "select * from #@__hotel where aid='$aid'";
//$dsql->SetQuery($sql);
//$dsql->Execute();
//$row = $dsql->GetArray();
$dpl = new DedeTemplate();
$tpl =$cfg_basedir.$cfg_templets_dir.'/default/188_order_hotel_2.htm';
$dpl->LoadTemplate($tpl);
$dpl->display();
	
?>